class nvgpu::driver inherits nvgpu {
        
  #TODO: set this to your gpu devices and provide appropriate driver files
  #case $gpu {
  #        'k-Series':{
  #            $nvpkg="NVIDIA-Linux-x86_64-340.65.run"
  #        }
  #	default: { notice ("Unknown GPU") }
  #}

  yumrepo { "cuda101":
        baseurl => "http://${mirrorserver}/yum/nvidia/cuda-10-1-rhel-7",
        descr => "cuda102",
        enabled => 1,
        gpgcheck => 0,
        before   => Yumrepo['site']
  } 
  case $operatingsystemmajrelease {
  '6':{
      $nvpkg = [ 
        "cuda-7-5",
        "cuda-8-0",
        "cuda-9-1",
        "cuda-10-0",
      ]
    }
   '7':{
      $nvpkg = [
        "cuda-10-1",
        "cuda-10-2",
        "cuda-11-0",
      ]
    }
  }

  package { $nvpkg:
  	ensure  => installed,
  	require => Package['cuda-drivers'],
  }
  package { "cuda-drivers":
        ensure  => installed,
        require => Package['wn75pkg'],
  }

  if $kmod_enable {
    package { "nvidia-kmod":
          ensure  => installed,
          require => Package['wn75pkg'],
    }->
    rclocal::script { "nvidia-smi":
      priority  => "10",
      autoexec  => false,
      content   => "nvidia-smi -pm 1",
    }

  }
  if $enable_cards {
    file { "/etc/slurm/gres.conf":
      ensure  => file,
      owner   => slurm,
      group   => slurm,
      content => template("nvgpu/gres.conf.erb"),
      mode    => '0644',
    }
    file { "/usr/local/libexec/slurm":
      ensure  => directory,
      recurse => true,
      owner  => root,
      group  => root,
      mode   => '0755',
      force  => true,
      source     =>  "puppet:///modules/${module_name}/slurm",
    } ->
    cron { "NVGPU-ecc-mem":
      command => "/usr/local/libexec/slurm/detect_reset_ecc_mem.sh > /dev/null 2>&1",
      user    => 'root',
      minute  => '*/30',
      hour    => '*',
    } -> 
    logrotate::rule { 'slurm-ecc-mem':
      path         => ['/var/log/slurm/slurm_ecc_mem.log.json' ],
      rotate       => 2,
      dateext      => true,
      rotate_every => 'week',
      minsize      => '100M',
      postrotate   => '/bin/touch /var/log/slurm/slurm_ecc_mem.log.json',
    }
    cron { "NVGPU-stuck-gpu":
      command => "/usr/local/libexec/slurm/stuck_nvdia_process_monitor.sh > /dev/null 2>&1",
      user    => 'root',
      minute  => '8',
      hour    => '*',
    }

  }
  #needs extra option to make it think CRT is connected
  #file { '/etc/X11/xorg.conf':
  #	source  => 'puppet:///modules/hpc-puppet/nvidia-xorg.conf',
  #		ensure  => present,
  #		require => Exec [ 'install-nvidia-driver' ],
  #	}
  
  #nvidia params for work with virtualGL
  #file { '/etc/modprobe.d/virtualgl.conf':
  #	source => 'puppet:///modules/hpc-puppet/nvidia-module.conf',
  #	ensure => present,
  #	require => Exec [ 'install-nvidia-driver' ],
  #}
}
